/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

 function deleteDuplicates(head: ListNode | null): ListNode | null {
  if (!head || !head.next) {
        return head
      }
  let isSame = head.val
      let preNode = head
      let compareNode = head.next
      while (compareNode) {
        if (compareNode.val === isSame) {
          preNode.next = compareNode.next
          compareNode = preNode.next
        } else {
          preNode = compareNode
          isSame = compareNode.val
          compareNode = preNode.next
        }
      }
      return head
};